package binaryTree.LayerOrderTraversal;

import java.util.LinkedList;
//求二叉树的深度
public class Basic104 {

    public int maxDepth(TreeNode root) {
        int maxDepth=0;
        LinkedList<TreeNode>  list = new LinkedList<>();
        if (root!=null){
            list.add(root);
        }
        while (!list.isEmpty()) {
            maxDepth++;
            int size = list.size();
            while (size > 0) {
                TreeNode cur = list.poll();
                if (cur.left!=null){
                    list.add(cur.left);
                }
                if (cur.right!=null){
                    list.add(cur.right);
                }
                size--;
            }
        }
        return  maxDepth;
    }

}
